package pers.qianyu.month_202012.date_20201225.dp_bag2;

/**
 * 700. 杆子分割
 * https://www.lintcode.com/problem/cutting-a-rod/description
 * - 完全背包求最值
 *
 * @author mizzle rain
 * @date 2020-12-25 21:29
 */
public class Cutting {
    /**
     * @param prices: the prices
     * @param n:      the length of rod
     * @return: the max value
     */
    public int cutting(int[] prices, int n) {
        int[] dp = new int[n + 1];
        for (int i = 0; i < prices.length; i++) {
            int weight = i + 1;
            int price = prices[i];
            for (int j = weight; j <= n; j++) {
                dp[j] = Math.max(dp[j], dp[j - weight] + price);
            }
        }
        return dp[n];
    }
}
